package com.yuanfeng.service.impl;

import com.yuanfeng.basedata.entiry.KcsjUser;
import com.yuanfeng.basedata.repository.UserRepository;
import com.yuanfeng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @ClassName UserServiceImpl
 * @Description T0D0
 * @Author yuanfeng
 * @Date 2019/9/6 21:50
 * @Version 1.0
 **/
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public List<KcsjUser> listUsers() {
        return userRepository.findAll();
    }

    @Override
    public Optional<KcsjUser> findOneUser(Integer userId) {
        return userRepository.findById(userId);
    }

    @Override
    public KcsjUser getOneKcsjUser(String userName,String userPassword) {
        return userRepository.findKcsjUserByUserNameAndUserPassword(userName,userPassword);
    }

    @Override
    public KcsjUser registerUser(KcsjUser kcsjUser) {
        return userRepository.save(kcsjUser);
    }

    @Override
    public int updateByUserId(String userName,
                              String userPassword,
                              String userEmail,
                              Date userBirthday,
                              String userAddress,
                              Integer userId) {
        return userRepository.updateUserInfoById(userName,
                userPassword,
                userEmail,
                userBirthday,
                userAddress,
                userId);
    }

}
